let url = $this.$util.getAPI_URL();
let formData = new FormData();
formData.append("id", $this.id);
url = url.replace("api", "task/taskbyId");

//建“状态 → 颜色”表（可扩展）
const statusMap = {
    "0": {bg: '#999', txt: '已保存'},
    "1": {bg: '#2db7f5', txt: '已派发'},
    "2": {bg: '#87d068', txt: '执行中'},
    "3": {bg: '#faad14', txt: '待审核'},
    "4": {bg: '#52c41a', txt: '已完成'},
    "5": {bg: '#ff4d4f', txt: '已取消'},
    "6": {bg: '#722ed1', txt: '暂停'},
    "7": {bg: '#13c2c2', txt: '重启'}
};

$this.$http.post(url, formData).then((res) => {
    if (res.data.code === 280) {
        let data = res.data.data[0]
        console.log("data = ", data)
        portalBoardStyle(data);
        if (data.input_1711505283971_PgltR == "true") {
            console.log("1")
            lcbStyle()
        } else {
            dellcbStyle()
        }
    }
})

let portalBoard = document.getElementsByClassName('portal-10')[0]


//  门户式样
function portalBoardStyle(data) {
    if (!portalBoard) return;
    if (portalBoard) {
        let newClass = 'portal-10'
        const val = data?.input_1711518795031_xvIfW;   // 0-7
        const style = statusMap[val] || statusMap[0];  // 取不到就按“已保存”灰掉
        // 定义样式
        var css = `
          .${newClass} .combineTabs_1711517331365_NqldR .basicInfo_1711517486526_NMZ0q .ant-row:nth-child(1) .ant-col:nth-child(10) div:nth-child(2) span,
          .${newClass} .combineTabs_1711517331365_NqldR .basicInfo_1711517486526_NMZ0q .ant-row:nth-child(1) .ant-col:nth-child(11) div:nth-child(2) span{
            background-color: rgb(45, 183, 245) !important;
            color: white !important;
            width: 40px !important;
            height: 20px !important;
            display: block !important;
            text-align: center !important;
          }
        `;
        $this.$util.appendHeadStyle('portal-10-all', "10", css); //动态为指定元素添加样式
        // 2. 第 12 列“随状态变色”
        /**
         * #app > div > div > div > div > div > div.ele-admin-main > div.ele-admin-body > div.ele-admin-content > div > div > div > div > div > div > div:nth-child(2) > div > div > div > div > div.ant-tabs-top-content.ant-tabs-content.ant-tabs-content-animated > div.ant-tabs-tabpane.ant-tabs-tabpane-active > div.ant-row > div:nth-child(2) > div > div > div > div > div:nth-child(12) > div > div.ant-col.ant-col-8.text-right.ellipsis > span
         * */
        let cssNew = `
      .combineTabs_1711517331365_NqldR .basicInfo_1711517486526_NMZ0q .ant-row:nth-child(1) .ant-col:nth-child(12) div:nth-child(2)  span {
        background-color: ${style.bg} !important;
        color: white !important;
        width: 60px !important;
        height: 20px !important;
        display: block !important;
        text-align: center !important;
      }
    `;
        $this.$util.appendHeadStyle('portal-10-lxy', "10", cssNew); //动态为指定元素添加样式


        /*css: 强制字符串样式显示
         combineTabs_1711517331365_NqldR 门户容器标识；
         basicInfo_1711517486526_NMZ0q 基本信息”这一整块的 class；antd 的 Row/Col 布局就长在这下面。
         .ant-row:nth-child(1)  基本信息里的 第一行（Row）
         .ant-col:nth-child(10)  与  .ant-col:nth-child(11)
         nth-child(2) 指的就是 “值” 那个盒子。
         字段值里再包一层 <span>，通常用来放纯文本或小标签同一行里 第 10 列 和 第 11 列（Col）。
        */
    }
}

function lcbStyle() {
    console.log("2")
    if (portalBoard) {
        let newClass = 'portal-10'
        // 定义样式
        var css = `
          .${newClass} .combineTabs_1711517331365_NqldR .basicInfo_1711517486526_NMZ0q .ant-row:nth-child(1) .ant-col:nth-child(18) div:nth-child(2) span{
            background-color: rgb(45, 183, 245) !important;
            color: white !important;
            width: 40px !important;
            height: 20px !important;
            display: block !  ;
            text-align: center !important;
          }
        `;
        $this.$util.appendHeadStyle('portal-10-lcb', "10", css);
    }
}


function dellcbStyle() {
    console.log("2")
    if (portalBoard) {
        let newClass = 'portal-10'
        // 定义样式
        var css = `
          .${newClass} .combineTabs_1711517331365_NqldR .basicInfo_1711517486526_NMZ0q .ant-row:nth-child(1) .ant-col:nth-child(18) div:nth-child(2) span{
          }
        `;
        $this.$util.appendHeadStyle('portal-10-lcb', "10", css);
    }
}
